package bank
{
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import utils.DisplayTool;
	
	import view.components.HintImgButton;
	import view.components.RemoteHtmlImg;
	import view.components.list.ITileListItem;
	
	public class ItemBank extends Sprite implements ITileListItem
	{
		private var face:RemoteHtmlImg;
		private var title:TextField;
		private var stoleSign:HintImgButton;
		private var _index:int;
		private var _selected:Boolean;
		private var _data:Object;
		private var bankLandControl:BankLandControl = BankLandControl.getInstance();
		
		public function ItemBank()
		{
			//this.mouseChildren = false;
			this.buttonMode = true;
			initFace();
			initTitle();
			initStoleSign();
		}
		
		private function initStoleSign():void
		{
			stoleSign = new HintImgButton(0,0,0,null,new Bitmap(ChestTool.stole),-1,-1,null);
			stoleSign.x = 100;
			stoleSign.info = "可取";
			addChild(stoleSign);
		}
		
		private function initTitle():void
		{
			title = new TextField();
			var tf:TextFormat = new TextFormat();
			tf.color = 0xFFFFFF;
			tf.size = 12;
			title.defaultTextFormat = tf;
			title.x = 32;
			title.selectable = false;
			title.width = 60;
			title.height = 20;
			addChild(title);
		}
		
		private function initFace():void
		{
			face = new RemoteHtmlImg(20,20);
			face.x = 10;
			addChild(face);
		}
		
		public function get self():DisplayObject
		{
			return this;
		}
		
		public function update(data:Object):void
		{
			_data = data;
			title.text = data.@name;
			face.loadImg(data.@image);
			
			if (data.@steal == "0")
			{
				stoleSign.visible = false;
			}
		}
		
		public function drawSelectBg():void
		{
			
			with(this.graphics)
			{
				clear();
				beginFill(0xFFFFFF,.5);
				drawRect(0,0,150,20);
				endFill();
			}
			
			bankLandControl.loadBankInfo(_data.@friendId);
		}
		
		public function drawOverBg():void
		{
		}
		
		public function drawOutBg():void
		{
			if (_selected)
			{
				return;
			}
			this.graphics.clear();
		}
		
		
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function set selected(v:Boolean):void
		{
			_selected = v;
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		public function get index():int
		{
			return _index;
		}
		
		public function set index(v:int):void
		{
			_index = v;
		}
		
		public function destroy():void
		{
			DisplayTool.removeAllChild(this);
			face.destroy();
			face = null;
			title = null;
			stoleSign.destroy();
			stoleSign = null;
		}
		
		public function getInstance():ITileListItem
		{
			return new ItemBank();
		}
		
		public function switchState(state:int):void
		{}
	}
}